package com.yiqi.lottery.feature.lottery.view.adapter;

import android.widget.CheckBox;
import android.widget.CompoundButton;
import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.utils.T;
import com.yiqi.lottery.R;
import com.yiqi.lottery.entity.bo.LuckyBo;
import com.yiqi.lottery.entity.bo.LuckySection;
import com.yiqi.lottery.entity.bo.SelectItem;
import com.yiqi.lottery.feature.lottery.view.LuckyNumberActivity;

import java.util.ArrayList;
import java.util.List;

public class  LuckyQianAdapter extends BaseSectionQuickAdapter<LuckySection, BaseViewHolder> {
    LuckyNumberActivity activity;
    private GetCheckedValue getCheckedValue;
    public LuckyQianAdapter(List<LuckySection> data) {
        super(R.layout.item_lottery_lucky_qian, R.layout.item_lottery_lucky_head, data);
    }


    @Override
    protected void convertHead(BaseViewHolder helper, LuckySection item) {
        helper.setText(R.id.tv_lottery_lucky_head, item.header);
    }

    @Override
    protected void convert(BaseViewHolder helper, LuckySection item) {
        final SelectItem selectItem = item.t;
        helper.setText(R.id.cb_lucky_qian, selectItem.getName() <= 9 ? "0" + selectItem.getName() : "" + selectItem.getName());
        CheckBox checkBox = helper.getView(R.id.cb_lucky_qian);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {



                if (selectItem.getType() == 1) {
                    if (isChecked) {
                        selectItem.setCheck(true);
                        checkBox.setBackground(AM.app().getResources().getDrawable(R.drawable.bg_lottery_qian_selected));
                        checkBox.setTextColor(AM.app().getResources().getColor(R.color.primary_comparison));
                    } else {
                        selectItem.setCheck(false);
                        checkBox.setBackground(AM.app().getResources().getDrawable(R.drawable.bg_lottery_qian_unselect));
                        checkBox.setTextColor(AM.app().getResources().getColor(R.color.primary_highlight));
                    }
                } else if (selectItem.getType() == 2) {
                    if (isChecked) {
                        selectItem.setCheck(true);
                        checkBox.setBackground(AM.app().getResources().getDrawable(R.drawable.bg_lottery_hou_selected));
                        checkBox.setTextColor(AM.app().getResources().getColor(R.color.primary_comparison));
                    } else {
                        selectItem.setCheck(false);
                        checkBox.setBackground(AM.app().getResources().getDrawable(R.drawable.bg_lottery_hou_unselect));
                        checkBox.setTextColor(AM.app().getResources().getColor(R.color.lottery_lucky_hou));
                    }
                }
                getCheckedValue.getValue();


            }
        });


        if (selectItem.getType() == 1) {
            if (selectItem.isCheck()) {

                checkBox.setBackground(AM.app().getResources().getDrawable(R.drawable.bg_lottery_qian_selected));
                checkBox.setTextColor(AM.app().getResources().getColor(R.color.primary_comparison));
            } else {

                checkBox.setBackground(AM.app().getResources().getDrawable(R.drawable.bg_lottery_qian_unselect));
                checkBox.setTextColor(AM.app().getResources().getColor(R.color.primary_highlight));
            }
        } else if (selectItem.getType() == 2) {

            if (selectItem.isCheck()) {
                checkBox.setBackground(AM.app().getResources().getDrawable(R.drawable.bg_lottery_hou_selected));
                checkBox.setTextColor(AM.app().getResources().getColor(R.color.primary_comparison));
            } else {
                checkBox.setBackground(AM.app().getResources().getDrawable(R.drawable.bg_lottery_hou_unselect));
                checkBox.setTextColor(AM.app().getResources().getColor(R.color.lottery_lucky_hou));
            }
        }

    }

    public  interface  GetCheckedValue{
        void getValue();
    }

    public void setOnItemChecked(GetCheckedValue getCheckedValue){
        this.getCheckedValue=getCheckedValue;
    }
}
